package case_library

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/case_library"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    case_libraryReq "github.com/flipped-aurora/gin-vue-admin/server/model/case_library/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "github.com/flipped-aurora/gin-vue-admin/server/utils"
)

type Case_structApi struct {
}

var case_Service = service.ServiceGroupApp.Case_libraryServiceGroup.Case_structService


// CreateCase_struct 创建Case_struct
// @Tags Case_struct
// @Summary 创建Case_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body case_library.Case_struct true "创建Case_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /case_/createCase_struct [post]
func (case_Api *Case_structApi) CreateCase_struct(c *gin.Context) {
	var case_ case_library.Case_struct
	err := c.ShouldBindJSON(&case_)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    verify := utils.Rules{
        "Manufacturing_serial_number":{utils.NotEmpty()},
        "Troubleshooting_date":{utils.NotEmpty()},
        "Process_design_document_number":{utils.NotEmpty()},
        "Responsible_craftman":{utils.NotEmpty()},
        "Fault_description":{utils.NotEmpty()},
        "Ata_chapter_level1":{utils.NotEmpty()},
        "Ata_chapter_level2":{utils.NotEmpty()},
    }
	if err := utils.Verify(case_, verify); err != nil {
    		response.FailWithMessage(err.Error(), c)
    		return
    	}
	if err := case_Service.CreateCase_struct(&case_); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteCase_struct 删除Case_struct
// @Tags Case_struct
// @Summary 删除Case_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body case_library.Case_struct true "删除Case_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /case_/deleteCase_struct [delete]
func (case_Api *Case_structApi) DeleteCase_struct(c *gin.Context) {
	var case_ case_library.Case_struct
	err := c.ShouldBindJSON(&case_)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := case_Service.DeleteCase_struct(case_); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteCase_structByIds 批量删除Case_struct
// @Tags Case_struct
// @Summary 批量删除Case_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除Case_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /case_/deleteCase_structByIds [delete]
func (case_Api *Case_structApi) DeleteCase_structByIds(c *gin.Context) {
	var IDS request.IdsReq
    err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := case_Service.DeleteCase_structByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateCase_struct 更新Case_struct
// @Tags Case_struct
// @Summary 更新Case_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body case_library.Case_struct true "更新Case_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /case_/updateCase_struct [put]
func (case_Api *Case_structApi) UpdateCase_struct(c *gin.Context) {
	var case_ case_library.Case_struct
	err := c.ShouldBindJSON(&case_)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
      verify := utils.Rules{
          "Manufacturing_serial_number":{utils.NotEmpty()},
          "Troubleshooting_date":{utils.NotEmpty()},
          "Process_design_document_number":{utils.NotEmpty()},
          "Responsible_craftman":{utils.NotEmpty()},
          "Fault_description":{utils.NotEmpty()},
          "Ata_chapter_level1":{utils.NotEmpty()},
          "Ata_chapter_level2":{utils.NotEmpty()},
      }
    if err := utils.Verify(case_, verify); err != nil {
      	response.FailWithMessage(err.Error(), c)
      	return
     }
	if err := case_Service.UpdateCase_struct(case_); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindCase_struct 用id查询Case_struct
// @Tags Case_struct
// @Summary 用id查询Case_struct
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query case_library.Case_struct true "用id查询Case_struct"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /case_/findCase_struct [get]
func (case_Api *Case_structApi) FindCase_struct(c *gin.Context) {
	var case_ case_library.Case_struct
	err := c.ShouldBindQuery(&case_)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if recase_, err := case_Service.GetCase_struct(case_.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"recase_": recase_}, c)
	}
}

// GetCase_structList 分页获取Case_struct列表
// @Tags Case_struct
// @Summary 分页获取Case_struct列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query case_libraryReq.Case_structSearch true "分页获取Case_struct列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /case_/getCase_structList [get]
func (case_Api *Case_structApi) GetCase_structList(c *gin.Context) {
	var pageInfo case_libraryReq.Case_structSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := case_Service.GetCase_structInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
